package com.mgq.netty.bytebuff;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

/*
* byteBuff和String转换
* */
public class TestByteBuffString {
    public static void main(String[] args) {
        //1.字符串转ByteBuff
        ByteBuffer byteBuffer = ByteBuffer.allocate(10);
        byteBuffer.put("hello".getBytes());

        //2.方法二 charSet
        ByteBuffer hello = StandardCharsets.UTF_8.encode("hello");

        //3.使用wrap
        ByteBuffer wrap = ByteBuffer.wrap("hello".getBytes());

        try (FileChannel channel = new RandomAccessFile("test.txt","r").getChannel()) {

        } catch (IOException e) {
        }
    }
}
